package com.zoulj.config;


import com.zoulj.util.IdWorker;
import com.zoulj.util.JwtUtil;
import com.zoulj.util.RedisOperator;
import com.zoulj.util.ValidateCodeUtils;
import org.redisson.Redisson;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AppConfig {

    interface Constant{
        String REDIS_IP_1 = "redis://127.0.0.1:6379";
        String REDIS_IP_2 = "";
        String REDIS_PASSWORD_1 = "";
        String REDIS_PASSWORD_2 = "";
    }

    @Bean
    public JwtUtil jwtUtil(){
        return new JwtUtil();
    }

    @Bean
    public RedisOperator redisOperator(){
        return new RedisOperator();
    }
    @Bean
    public ValidateCodeUtils validateCodeUtils(){
        return new ValidateCodeUtils();
    }

    @Bean
    public IdWorker idWorker(){
        return new IdWorker();
    }

    @Bean
    public Redisson redisson(){
        //此为单机模式
        Config config = new Config();
        config.useSingleServer().setAddress(Constant.REDIS_IP_1).setDatabase(0);
        return (Redisson) Redisson.create(config);
    }

}
